/**
 *
 * 获取用户信息接口
 *
 */
const router = require('express').Router();
const tips = require('../../../common/tips');
const RSA = require('../../../common/RSAClass');


router.post('/getuserinfo', async (req, res, next) => {
    console.log('getuserinfo api login');

    const uid = req.body.uid;
    let xbtk = req.cookies.get('xbtk');
    if(!xbtk || !uid) {
        res.json({
            code:tips.user.infoFailCode,
            msg:tips.user.infoFail
        });
        return;
    }
    // 私钥解密
    xbtk = await new RSA().decrypt(xbtk);
    const userId = parseInt(xbtk) - parseInt(uid);

    try {
        const info_rows = '';
        if (info_rows.length) {
            res.json({
                code: tips.success,
                msg: tips.successCode,
                data: info_rows[0]
            });
        } else {
            console.log(tips.find.fail);
            res.json({
                code: tips.find.failCode,
                msg: tips.find.fail
            });
        }
    } catch (e) {
        console.error(tips.sql.selectFail + e);
    }

    return;
});

module.exports = router;